Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

super-media-element

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

super-media-element

Helps you create a custom element w/ a HTMLMediaElement API.

  • 0.4.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
959
increased by57.99%
Maintainers
1
Weekly downloads
 
Created
Source

Super Media Element

A custom element that helps save alienated player API's to bring back their true inner HTMLMediaElement API, or to extend a native media element like <audio> or <video>.

Usage

import { SuperVideoElement } from 'super-media-element';

class MyVideoElement extends SuperVideoElement {
  constructor() {
    super();

    this.loadComplete = new Promise((resolve) => {
      this.loadResolve = resolve;
    });
  }

  async attributeChangedCallback(attrName, oldValue, newValue) {
    // This is required to come before the await for resolving loadComplete.
    if (attrName === 'src' && newValue) {
      this.load();
      return;
    }

    super.attributeChangedCallback(attrName, oldValue, newValue);
  }

  async load() {
    if (this.hasLoaded) {
      this.loadComplete = new Promise((resolve) => {
        this.loadResolve = resolve;
      });
    }
    this.hasLoaded = true;

    // Wait 1 tick to allow other attributes to be set.
    await Promise.resolve();

    // code to load a video element from a script
    // example: https://github.com/luwes/jwplayer-video-element/blob/main/src/jwplayer-video-element.js#L49-L69

    this.loadResolve();
  }

  get nativeEl() {
    return this.querySelector('.loaded-video-element');
  }

  get src() {
    return this.getAttribute('src');
  }

  set src(val) {
    if (this.src == val) return;
    this.setAttribute('src', val);
  }
}

if (!globalThis.customElements.get('my-video')) {
  globalThis.customElements.define('my-video', MyVideoElement);
}

export { MyVideoElement };

Keywords

FAQs

Package last updated on 28 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc